<?php
class SubjectController extends BaseController
{
    public function __construct($uri)
    {
        parent::__construct($uri);
    }

    /**
     * id从uri中获得
     * web server判断静态文件是否存在，如果不存在进入php
     * 触发请求豆瓣api获得名称和评分，保存到数据库
     * 静态化
     * 用户上传种子后，bt静态化，异步(todo)：重新请求豆瓣api，更新名字和评分
     * 登录按钮用js检测cookie，pt用ajax
     */
    public function get()
    {
        $tmp = explode('/', $this->uri);
        $id = $tmp[2];
        $m = new MovieModel();
        $r = array();
        $r['movie'] = $m->get($id);
        $r['movie_uri'] = $m->getUri($id);
        $providers = $m->getProviders();
        foreach($providers as $v) {
            $r['providers'][$v['id']] = $v['name'];
        }
        $r['resolution'] = array_flip(MovieUriDb::$resolution);
        $this->output['http']['cache-control'] = array(
            'public',
            'max-age' => 60, //todo 为什么定60
        );
        $this->output['tpl'] = 'subject/get';
        $this->output['data'] = $r;
        return $this->output;
    }
}
?>
